<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>1_refs</title>
    <style>
        .input_label {
            margin-left: 10px;
        }
    </style>
</head>
<body>
<!--准备好一个容器-->
<div id="test">

</div>
</body>

<!--核心库引入顺序，必须先是核心库然后在引入dom库-->
<script src="../js/react.development.js" crossorigin></script>
<!--用于支持react操作dom-->
<script src="../js/react-dom.development.js"></script>
<!--引入babel，用于将jsx转为js-->
<script src="../js/babel.min.js"></script>

<script type="text/babel">
    //1·定义组件
    class Demo extends React.Component {
        render() {
            return (
                <div>
                    <label className="input_label">
                        <input ref="input1" type="text" placeholder="点击按钮提示数据"/>
                    </label>
                    <button onClick={this.showData} className="input_label">点我提示左侧数据</button>
                    <label className="input_label">
                        <input ref="input2" type="text" onBlur={this.showData2} placeholder="失去焦点提示数据"/>
                    </label>
                </div>
            )
        }

        //展示左侧输入框的数据
        showData = () => {
            let {input1} = this.refs;
            alert(input1.value)
        }
        //展示右侧输入框数据
        showData2 = () => {
            let {input2} = this.refs;
            alert(input2.value)
        }
    }

    //2·渲染组件
    ReactDOM.render(<Demo/>, document.getElementById('test'))
</script>
</html>